package db

import "gitee.com/makitdone/gweb/v2"

// 获取符合条件的第一条记录
func First[T any](db *gweb.DB, conds ...interface{}) *T {
	var t T
	if err := db.Model(&t).First(&t, conds...); err != nil {
		return nil
	} else {
		return &t
	}
}

func FindAll[T any](db *gweb.DB, conds ...any) ([]T, error) {
	var dest []T
	var t T
	if err := db.Model(&t).Find(&dest, conds); err != nil {
		return dest, err
	} else {
		return dest, nil
	}
}

func Create[T any](db *gweb.DB, value ...any) error {
	return db.Create(value...)
}

func CreateBatches[T any](tx *gweb.DB, value any, batchSize int) error {
	return tx.CreateInBatches(value, batchSize)
}
